<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no"/>
    <title>添加产品</title>
    <link rel="icon" href="static/images/favicon.ico" type="image/ico">
    <meta charset="utf-8">
    <title>富文本编辑器（WYSIWYG）</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta name="keywords"
          content="编辑器,在线编辑器,富文本编辑器,所见即所得编辑器,opensource rich wysiwyg text editor jquery bootstrap execCommand html5"/>
    <meta name="description" content="这个微型的JQuery Bootstrap WYSIWYG 插件能将任何DIV变为HTML5富文本编辑器"/>
    <!-- 样式 -->
    <link href="static/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
    <link href="http://netdna.bootstrapcdn.com/font-awesome/3.0.2/css/font-awesome.css" rel="stylesheet">
    <link href="static/css/index.css" rel="stylesheet">

    <!--    头部公共文件-->
    <div th:replace="public/pc :: top"></div>
</head>
<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <div th:replace="public/pc :: navigation"></div>
        <!--End 左侧导航-->

        <!--头部信息-->
        <div th:replace="public/pc :: head"></div>
        <!--End 头部信息-->
        <!--页面主要内容-->
        <main class="lyear-layout-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">
                                <form action="#!" method="post" class="row">
                                    <div class="form-group col-md-12">
                                        <label for="category">分类</label>
                                        <div class="form-controls">
                                            <select name="type" class="form-control" id="category">
                                                <!--                        数据在后台获取-->
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group col-md-4">
                                        <label for="productEncode">产品编码</label>
                                        <input type="text" class="form-control" id="productEncode" name="productEncode"
                                               value=""
                                               placeholder="请输入产品编码"/>
                                    </div>
                                    <div class="form-group col-md-4">
                                        <label for="productName">产品名称</label>
                                        <input type="text" class="form-control" id="productName" name="productName"
                                               value=""
                                               placeholder="请输入产品名称"/>
                                    </div>
                                    <div class="form-group col-md-4">
                                        <label for="purchasePrice">进货价</label>
                                        <input type="text" class="form-control" id="purchasePrice" name="purchasePrice"
                                               value=""
                                               placeholder="请输入进货价"/>
                                    </div>
                                    <div class="form-group col-md-4">
                                        <label for="salesPrice">销售价</label>
                                        <input type="text" class="form-control" id="salesPrice" name="salesPrice"
                                               value=""
                                               placeholder="请输入销售价"/>
                                    </div>
                                    <div class="form-group col-md-4">
                                        <label for="unit">单位</label>
                                        <input type="text" class="form-control" id="unit" name="unit" value=""
                                               placeholder="请输入单位"/>
                                    </div>
                                    <div class="form-group col-md-4">
                                        <label for="inventory">库存</label>
                                        <input type="text" class="form-control" id="inventory" name="inventory" value=""
                                               placeholder="请输入库存"/>
                                    </div>
                                    <div class="form-group col-md-4">
                                        <label for="shelfLife">保质期</label>
                                        <input type="text" class="form-control" id="shelfLife" name="shelfLife" value=""
                                               placeholder="请输入保质期"/>
                                    </div>
                                    <div class="form-group col-md-12">
                                        <label>首页展示图</label>
                                        <div class="form-controls">
                                            <ul class="list-inline clearfix lyear-uploads-pic">
                                                <li class="col-xs-4 col-sm-5 col-md-2" id="indexShowImage">
                                                    <!-- 用于读取图片 -->
                                                    <input class="input-img" id="indexImage" name="imageFile"
                                                           type="file" accept="image/*"
                                                           style="display: none;">
                                                    <input type="hidden" id="image" name="image">
                                                    <!-- 用于触发事件 -->
                                                    <a class="pic-add" id="addIndexImage" href="#!" title="点击上传"></a>
                                                </li>
                                            </ul>
                                        </div>
                                    </div>
                                    <div class="form-group col-md-12">
                                        <label>产品主图</label>
                                        <div class="form-controls">
                                            <ul class="list-inline clearfix lyear-uploads-pic" id="imageList">
                                                <!--                                                <li class="col-xs-4 col-sm-3 col-md-2">-->
                                                <!--                                                    <figure>-->
                                                <!--                                                        <img src="static/images/gallery/15.jpg" alt="图片一">-->
                                                <!--                                                        <figcaption>-->
                                                <!--                                                            <a class="btn btn-round btn-square btn-primary" href="#!"><i-->
                                                <!--                                                                    class="mdi mdi-eye"></i></a>-->
                                                <!--                                                            <a class="btn btn-round btn-square btn-danger" href="#!"><i-->
                                                <!--                                                                    class="mdi mdi-delete"></i></a>-->
                                                <!--                                                        </figcaption>-->
                                                <!--                                                    </figure>-->
                                                <!--                                                </li>-->
                                                <!--                                                <li class="col-xs-4 col-sm-3 col-md-2">-->
                                                <!--                                                    <figure>-->
                                                <!--                                                        <img src="static/images/gallery/16.jpg" alt="图片二">-->
                                                <!--                                                        <figcaption>-->
                                                <!--                                                            <a class="btn btn-round btn-square btn-primary" href="#!"><i-->
                                                <!--                                                                    class="mdi mdi-eye"></i></a>-->
                                                <!--                                                            <a class="btn btn-round btn-square btn-danger" href="#!"><i-->
                                                <!--                                                                    class="mdi mdi-delete"></i></a>-->
                                                <!--                                                        </figcaption>-->
                                                <!--                                                    </figure>-->
                                                <!--                                                </li>-->
                                                <!--                                                <li class="col-xs-4 col-sm-3 col-md-2">-->
                                                <!--                                                    <figure>-->
                                                <!--                                                        <img src="static/images/gallery/17.jpg" alt="图片三">-->
                                                <!--                                                        <figcaption>-->
                                                <!--                                                            <a class="btn btn-round btn-square btn-primary" href="#!"><i-->
                                                <!--                                                                    class="mdi mdi-eye"></i></a>-->
                                                <!--                                                            <a class="btn btn-round btn-square btn-danger" href="#!"><i-->
                                                <!--                                                                    class="mdi mdi-delete"></i></a>-->
                                                <!--                                                        </figcaption>-->
                                                <!--                                                    </figure>-->
                                                <!--                                                </li>-->
                                            </ul>
                                        </div>
                                    </div>
                                    <div class="form-group col-md-12">
                                        <div class="form-controls">
                                            <ul class="list-inline clearfix lyear-uploads-pic">
                                                <li class="col-xs-4 col-sm-3 col-md-2">
                                                    <!-- 用于读取图片 -->
                                                    <input class="input-img" id="images" name="imageFile"
                                                           type="file" accept="image/*"
                                                           style="display: none;">
                                                    <!-- <input type="hidden" id="images" name="images">-->
                                                    <!-- 用于触发事件 -->
                                                    <a class="pic-add" id="addImages" href="#!" onclick="addImages()"
                                                       title="点击上传"></a>
                                                </li>
                                            </ul>
                                        </div>
                                    </div>
                                    <div class="form-group col-md-12">
                                        <label for="description">描述</label>
                                        <textarea class="form-control" id="description" name="seo_description"
                                                  rows="5" value="" placeholder="描述"></textarea>
                                    </div>

                                    <div class="form-group col-md-12">
                                        <label for="description">图文详情</label>
                                        <!--        富文本-->
                                        <div class="container">
                                            <div class="hero-unit">
                                                <div class="btn-toolbar" data-role="editor-toolbar"
                                                     data-target="#editor">
                                                    <div class="btn-group">
                                                        <a class="btn dropdown-toggle" data-toggle="dropdown"
                                                           title="字体大小"><i
                                                                class="icon-font"></i><b
                                                                class="caret"></b></a>
                                                        <ul class="dropdown-menu">
                                                        </ul>
                                                    </div>
                                                    <!-- 字体 -->
                                                    <div class="btn-group">
                                                        <a class="btn dropdown-toggle" data-toggle="dropdown"
                                                           title="Font Size"><i
                                                                class="icon-text-height"></i>&nbsp;<b
                                                                class="caret"></b></a>
                                                        <ul class="dropdown-menu">
                                                            <li><a data-edit="fontSize 5"><font size="5">Huge</font></a>
                                                            </li>
                                                            <li><a data-edit="fontSize 3"><font
                                                                    size="3">Normal</font></a>
                                                            </li>
                                                            <li><a data-edit="fontSize 1"><font
                                                                    size="1">Small</font></a>
                                                            </li>
                                                        </ul>
                                                    </div>
                                                    <!-- 字体样式 -->
                                                    <div class="btn-group">
                                                        <a class="btn" data-edit="bold" title="Bold (Ctrl/Cmd+B)"><i
                                                                class="icon-bold"></i></a>
                                                        <a class="btn" data-edit="italic" title="Italic (Ctrl/Cmd+I)"><i
                                                                class="icon-italic"></i></a>
                                                        <a class="btn" data-edit="strikethrough"
                                                           title="Strikethrough"><i
                                                                class="icon-strikethrough"></i></a>
                                                        <a class="btn" data-edit="underline"
                                                           title="Underline (Ctrl/Cmd+U)"><i
                                                                class="icon-underline"></i></a>
                                                    </div>
                                                    <!-- 序列化 -->
                                                    <div class="btn-group">
                                                        <a class="btn" data-edit="insertunorderedlist"
                                                           title="Bullet list"><i
                                                                class="icon-list-ul"></i></a>
                                                        <a class="btn" data-edit="insertorderedlist"
                                                           title="Number list"><i
                                                                class="icon-list-ol"></i></a>
                                                        <a class="btn" data-edit="outdent"
                                                           title="Reduce indent (Shift+Tab)"><i
                                                                class="icon-indent-left"></i></a>
                                                        <a class="btn" data-edit="indent" title="Indent (Tab)"><i
                                                                class="icon-indent-right"></i></a>
                                                    </div>
                                                    <!-- 内容位置 -->
                                                    <div class="btn-group">
                                                        <a class="btn" data-edit="justifyleft"
                                                           title="Align Left (Ctrl/Cmd+L)"><i
                                                                class="icon-align-left"></i></a>
                                                        <a class="btn" data-edit="justifycenter"
                                                           title="Center (Ctrl/Cmd+E)"><i
                                                                class="icon-align-center"></i></a>
                                                        <a class="btn" data-edit="justifyright"
                                                           title="Align Right (Ctrl/Cmd+R)"><i
                                                                class="icon-align-right"></i></a>
                                                        <a class="btn" data-edit="justifyfull"
                                                           title="Justify (Ctrl/Cmd+J)"><i
                                                                class="icon-align-justify"></i></a>
                                                    </div>
                                                    <div class="btn-group">
                                                        <a class="btn dropdown-toggle" data-toggle="dropdown"
                                                           title="Hyperlink"><i
                                                                class="icon-link"></i></a>
                                                        <div class="dropdown-menu input-append">
                                                            <input class="span2" placeholder="URL" type="text"
                                                                   data-edit="createLink"/>
                                                            <button class="btn" type="button">Add</button>
                                                        </div>
                                                        <a class="btn" data-edit="unlink" title="Remove Hyperlink"><i
                                                                class="icon-cut"></i></a>

                                                    </div>

                                                    <div class="btn-group">
                                                        <a class="btn" title="Insert picture (or just drag & drop)"
                                                           id="pictureBtn"><i
                                                                class="icon-picture"></i></a>
                                                        <input type="file" data-role="magic-overlay"
                                                               data-target="#pictureBtn"
                                                               data-edit="insertImage"/>
                                                    </div>
                                                    <div class="btn-group">
                                                        <a class="btn" data-edit="undo" title="Undo (Ctrl/Cmd+Z)"><i
                                                                class="icon-undo"></i></a>
                                                        <a class="btn" data-edit="redo" title="Redo (Ctrl/Cmd+Y)"><i
                                                                class="icon-repeat"></i></a>
                                                    </div>
                                                    <input type="text" data-edit="inserttext" id="voiceBtn"
                                                           x-webkit-speech="">
                                                </div>
                                                <div id="editor">
                                                    Go ！！！
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group col-md-12">
                                        <label for="sort">排序</label>
                                        <input type="text" class="form-control" id="sort" name="sort" value="0"/>
                                    </div>
                                    <div class="form-group col-md-12">
                                        <label>状态</label>
                                        <div class="clearfix">
                                            <label class="lyear-radio radio-inline radio-primary">
                                                <input type="radio" name="status" value="0" checked><span>启用</span>
                                            </label>
                                            <label class="lyear-radio radio-inline radio-primary">
                                                <input type="radio" name="status" value="1"><span>禁用</span>
                                            </label>
                                        </div>
                                    </div>
                                    <div class="form-group col-md-12">
                                        <button type="button" id="addProduct" class="btn btn-primary ajax-post"
                                                target-form="add-form">确 定
                                        </button>
                                        <button type="button" class="btn btn-default"
                                                onclick="javascript:history.back(-1);return false;">返 回
                                        </button>
                                    </div>

                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
        <!--End 页面主要内容-->
    </div>
</div>

<script type="text/javascript" src="static/js/jquery.min.js"></script>
<script type="text/javascript" src="static/js/bootstrap.min.js"></script>
<script type="text/javascript" src="static/js/perfect-scrollbar.min.js"></script>
<!--标签插件-->
<script src="static/js/jquery-tags-input/jquery.tagsinput.min.js"></script>
<script type="text/javascript" src="static/js/main.min.js"></script>
<!--消息提示-->
<script type="text/javascript" src="static/js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="static/js/lightyear.js"></script>

<!--<script src="static/js/jquery.min.js"></script>-->
<script src="static/js/jquery.hotkeys.js"></script>
<!--<script src="static/js/bootstrap.min.js"></script>-->
<script src="static/js/bootstrap-wysiwyg.js"></script>
<!--富文本js-->
<script>
    $(function () {
        function initToolbarBootstrapBindings() {
            //定义字体样式
            var fonts = ['Serif', 'Sans', 'Arial', 'Arial Black', 'Courier',
                    'Courier New', 'Comic Sans MS', 'Helvetica', 'Impact', 'Lucida Grande', 'Lucida Sans', 'Tahoma', 'Times',
                    'Times New Roman', 'Verdana'],
                fontTarget = $('[title=Font]').siblings('.dropdown-menu');
            $.each(fonts, function (idx, fontName) {
                fontTarget.append($('<li><a data-edit="fontName ' + fontName + '" style="font-family:\'' + fontName + '\'">' + fontName + '</a></li>'));
            });
            $('a[title]').tooltip({container: 'body'});
            $('.dropdown-menu input').click(function () {
                return false;
            })
                .change(function () {
                    $(this).parent('.dropdown-menu').siblings('.dropdown-toggle').dropdown('toggle');
                })
                .keydown('esc', function () {
                    this.value = '';
                    $(this).change();
                });

            $('[data-role=magic-overlay]').each(function () {
                var overlay = $(this), target = $(overlay.data('target'));
                overlay.css('opacity', 0).css('position', 'absolute').offset(target.offset()).width(target.outerWidth()).height(target.outerHeight());
            });
            $('#voiceBtn').hide();
            // if ("onwebkitspeechchange"  in document.createElement("input")) {
            //   var editorOffset = $('#editor').offset();
            //   $('#voiceBtn').css('position','absolute').offset({top: editorOffset.top, left: editorOffset.left+$('#editor').innerWidth()-35});
            // } else {
            //   $('#voiceBtn').hide();
            // }
        };
        initToolbarBootstrapBindings();
        $('#editor').wysiwyg();
        window.prettyPrint && prettyPrint();
    });
</script>

<script type="text/javascript">
    // 参数
    let image = "";
    let sort = 0; // 图片排序
    let productId;

    // 页面加载时执行
    $(function () {
        // 首先获取一个id
        $.ajax({
            url: '/snowFlake/getDefaultId',
            method: 'post',
            data: {},
            dataType: "json",
            success: function (data) {
                console.log(data);
                if (data.code === 200) {
                    productId = data.data.id;
                } else {
                    alert("获取参数失败，请刷新页面！")
                }
            }
        })


    });

    // 触发文件上传事件
    $('#addIndexImage').click(function () {
        $('#indexImage').click()
    })

    $('#indexImage').on('change', function () {
        var file = $('.input-img').get(0).files[0]
        if (!file || file.length == 0) {
            return
        }
        var fileName = file.name;
        var fileType = fileName.substr(fileName.lastIndexOf(".")).toUpperCase();
        if (fileType !== ".GIF" && fileType !== ".PNG" && fileType !== ".JPG" && fileType !== ".JPEG") {
            alert('请选择图片文件！') // 提示
            return
        }
        const isLt2M = file.size / 1024 / 1024 < 2;
        if (!isLt2M) {
            alert('上传图片大小不能超过 2MB！') // 提示
            $('.input-img').get(0).value = ''
            return
        }

        // 有时候，我们上传图片时，需要将图片先预览，那么我们可以将图片转化为 base64 并展示出来
        $('.img').attr('src', fileToBase64(file))

        var formdata = new FormData()
        formdata.append("imageFile", file)

        lightyear.loading('show');
        $.ajax({
            url: '/image/upload2',
            method: 'post',
            data: formdata,
            processData: false, // 不需要数据序列化，因为传输的数据是 FormData 对象
            contentType: false, // 不需要带有 headers 的 content-type 字段，因为传递 FormData 对象就已经默认了 mutipart/form-data
            xhr: function () {
                var xhr = new XMLHttpRequest()
                xhr.upload.addEventListener('progress', function (e) {
                    if (e.lengthComputable) {
                        var progress = Math.round(e.loaded * 100 / e.total) + '%'
                        console.log('上传进度：', progress)
                    } else {
                        console.log('无法计算上传进度')
                    }
                })
                xhr.upload.addEventListener('load', function (e) {
                    console.log('上传成功')
                })
                xhr.upload.addEventListener('error', function (e) {
                    console.log('上传失败')
                })
                xhr.upload.addEventListener('abort', function (e) {
                    console.log('用户取消上传/浏览器断开了连接')
                })
                return xhr
            }
        }).done(function (data) {
            lightyear.loading('hide');
            image = data.data.url;
            let ghtml = "";
            console.log('后端返回的信息：')
            console.log(data);
            //    上传成功之后将图片回显到页面
            if (null != data.data && data.code === 200) {
                lightyear.notify(data.msg, 'success', 300);
                $("#image").val(data.data.url);
                ghtml += '<figure>';
                ghtml += '<img src= "' + data.data.url + '" alt="首页展示图片">';
                ghtml += '<figcaption>';
                ghtml += '<a class ="btn btn-round btn-square btn-primary" href="#!"><i class ="mdi mdi-eye"></i></a>';
                ghtml += '<a class ="btn btn-round btn-square btn-danger" href="#!"><i class ="mdi mdi-delete"></i></a>';
                ghtml += '</figcaption>';
                ghtml += '</figure>';
                $("#indexShowImage").html(ghtml); // 添加数据
            } else {
                lightyear.notify(data.msg, 'danger', 100);
            }
        }).fail(function (err) {
            console.log(err)
        })
    })

    /**
     * 触发图片上传
     */
    // 触发文件上传事件
    function addImages() {
        $('#images').click();
    }

    /**
     * 图片上传方法抽取
     */
    $('.input-img').on('change', function (e) {
        console.log(e);
        imgUpload(e);
    })

    function imgUpload(e) {
        var file = e.target.files[0];
        if (!file || file.length === 0) {
            return
        }
        var fileName = file.name;
        var fileType = fileName.substr(fileName.lastIndexOf(".")).toUpperCase();
        if (fileType !== ".GIF" && fileType !== ".PNG" && fileType !== ".JPG" && fileType !== ".JPEG") {
            alert('请选择图片文件！') // 提示
            return
        }
        const isLt2M = file.size / 1024 / 1024 < 2;
        if (!isLt2M) {
            alert('上传图片大小不能超过 2MB！') // 提示
            $('#images').get(0).value = ''
            return
        }

        // 有时候，我们上传图片时，需要将图片先预览，那么我们可以将图片转化为 base64 并展示出来
        $('.img').attr('src', fileToBase64(file))

        var formdata = new FormData()
        formdata.append("imageFile", file)
        lightyear.loading('show');
        $.ajax({
            url: '/image/upload2',
            method: 'post',
            data: formdata,
            processData: false, // 不需要数据序列化，因为传输的数据是 FormData 对象
            contentType: false, // 不需要带有 headers 的 content-type 字段，因为传递 FormData 对象就已经默认了 mutipart/form-data
            xhr: function () {
                var xhr = new XMLHttpRequest()
                xhr.upload.addEventListener('progress', function (e) {
                    if (e.lengthComputable) {
                        var progress = Math.round(e.loaded * 100 / e.total) + '%'
                        console.log('上传进度：', progress)
                    } else {
                        console.log('无法计算上传进度')
                    }
                })
                xhr.upload.addEventListener('load', function (e) {
                    console.log('上传成功')
                })
                xhr.upload.addEventListener('error', function (e) {
                    console.log('上传失败')
                })
                xhr.upload.addEventListener('abort', function (e) {
                    console.log('用户取消上传/浏览器断开了连接')
                })
                return xhr
            }
        }).done(function (data) {
            console.log('后端返回的信息：')
            console.log(data);
            if (null != data.data && data.code === 200) {
                $.ajax({
                    type: "post",
                    url: "/productImg/addProductImg",
                    data: {
                        productId: productId,
                        imgUrl: data.data.url,
                        type: 0,
                        sort: sort++
                    },
                    dataType: "json",
                    success: function (data) {
                        lightyear.loading('hide');
                        // 获取提示信息
                        if (data.code === 200) {
                            lightyear.notify(data.msg, 'success', 300);
                        } else {
                            lightyear.notify(data.msg, 'danger', 100);
                        }
                    }
                })
                // 调用图片展示的方法
                setTimeout(function () {
                    showImages();
                }, 1500);  //1.5秒后将会调用执行showImages()函数

            } else {
                lightyear.loading('hide');
                lightyear.notify(data.msg, 'danger', 100);
            }
        }).fail(function (err) {
            console.log(err)
        })
    }

    /**
     * 展示主图列表
     */
    function showImages() {
        let ghtml = "";
        // 根据产品id获取数据
        $.ajax({
            type: "post",
            url: "/productImg/getProductImg",
            data: {
                productId: productId
            },
            dataType: "json",
            success: function (data) {
                lightyear.loading('hide');
                // 获取提示信息
                if (data.code === 200) {
                    console.log(data);
                    // 填充数据
                    $.each(data.data, function (i, item) {
                        console.log(item);
                        // 添加数据信息
                        if (data.data.length > 0) {
                            ghtml += '<li class="col-xs-4 col-sm-3 col-md-2">';
                            ghtml += '<figure>';
                            ghtml += '<img src= "' + item.imgUrl + '" alt="首页展示图片">';
                            ghtml += '<figcaption>';
                            ghtml += '<a class ="btn btn-round btn-square btn-primary" href="#!"><i class ="mdi mdi-eye"></i></a>';
                            ghtml += '<a class ="btn btn-round btn-square btn-danger" href="#!"><i class ="mdi mdi-delete"></i></a>';
                            ghtml += '</figcaption>';
                            ghtml += '</figure>';
                            ghtml += '</li>';
                        }
                        // if (data.data.length <= 5) {
                        //     ghtml += '<li class="col-xs-4 col-sm-3 col-md-2">';
                        //     ghtml += '<input class="input-img" id="images" name="imageFile" type="file" accept="image/*" onchange="imgUpload()" style="display: none;">'
                        //     ghtml += '<a class="pic-add" id="addImages" href="#!" onclick="addImages()" title="点击上传"></a>';
                        //     ghtml += '</li>';
                        // }
                    })
                    $("#imageList").html(ghtml); // 添加数据
                } else {
                    lightyear.notify(data.msg, 'danger', 100);
                    return;
                }
            }
        })
    }

    /**
     * 文件流转为 base64
     * @param {*} file
     */
    function fileToBase64(file) {
        var URL = window.URL || window.webkitURL;
        return URL.createObjectURL(file);
    }


    // 添加数据
    $("#addProduct").click(function () {
        // 获取富文本数据信息
        let editor = $("#editor").html();
        console.log(editor);

        lightyear.loading('show');
        let categoryId = $("#category").val();
        let productEncode = $("#productEncode").val();
        // let image = $("#image").val();
        let productName = $("#productName").val();
        let purchasePrice = $("#purchasePrice").val();
        let salesPrice = $("#salesPrice").val();
        let unit = $("#unit").val();
        let inventory = $("#inventory").val();
        let shelfLife = $("#shelfLife").val();
        let description = $("#description").val();
        let sort = $("#sort").val();
        let status = $("input[name='status']:checked").val();
        // 判断数据是否为空
        if (0 === productEncode.length || 0 === productName.length || 0 === purchasePrice.length || 0 === salesPrice || 0 === unit.length || 0 === inventory.length || 0 === shelfLife.length) {
            lightyear.loading('hide');
            lightyear.notify("参数不能为空！请填写所有参数", 'danger', 100);
            return;
        }
        $.ajax({
            type: "post",
            url: "/productInfo/addProductInfo",
            data: {
                id: productId,
                categoryId: categoryId,
                productEncode: productEncode,
                image: image,
                productName: productName,
                purchasePrice: purchasePrice,
                salesPrice: salesPrice,
                unit: unit,
                inventory: inventory,
                shelfLife: shelfLife,
                description: description,
                sort: sort,
                status: status
            },
            dataType: "json",
            success: function (data) {
                lightyear.loading('hide');
                // 添加成功之后清空所填写的数据
                if (data.code === 200) {
                    lightyear.notify(data.msg, 'success', 300);
                    // 刷新当前页面
                    location.reload();
                } else {
                    lightyear.loading('hide');
                    lightyear.notify(data.msg, 'danger', 100);
                }
            }
        })
    })

</script>

</body>
</html>